package com.qq.first_project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qq.first_project.entity.Blog;
import com.qq.first_project.entity.vo.FirstPageBlogVo;
import com.qq.first_project.entity.vo.ShowBlogVo;
import com.qq.first_project.mapper.BlogMapper;
import com.qq.first_project.entity.vo.BlogVo;
import com.qq.first_project.service.BlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Qiu
 * @since 2023-01-30
 */
@Service
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {
    @Autowired
    @Resource
    private BlogMapper blogMapper;

    @Override
    public int saveBlog(Blog blog) {
        blog.setViews(0);
        blog.setCommentCount(0);
        return blogMapper.saveBlog(blog);
    }

    @Override
    public IPage<BlogVo> getAllBlogQuery(Page<BlogVo> page, String title) {
        return blogMapper.getAllBlogQuery(page,title);
    }

    @Override
    public int updateBlog(ShowBlogVo showBlogVo) {
        return blogMapper.updateBlog(showBlogVo);
    }

    @Override
    public ShowBlogVo getBlogById(Long id) {
        return blogMapper.getBlogById(id);
    }

    @Override
    public FirstPageBlogVo getIndexBlogById(Long id) {
        return blogMapper.getIndexBlogById(id);
    }

    //查询首页最新博客列表信息
    @Override
    public Page getAllFirstPageBlog(Page page) {
        return blogMapper.getAllFirstPageBlog(page);
    }

    //查询首页最新推荐信息
    @Override
    public List<FirstPageBlogVo> getRecommendedBlog() {
        List<FirstPageBlogVo> allRecommendBlog = blogMapper.getRecommendedBlog();
        return allRecommendBlog;
    }

    //根据标题或博客内容搜索博客端文章
    @Override
    public List<FirstPageBlogVo> getSearchBlog(String query) {
        return blogMapper.getSearchBlog(query);
    }

    //统计博客总数
    @Override
    public Integer getBlogTotal() {
        return blogMapper.getBlogTotal();
    }

    //统计访问总数
    @Override
    public Integer getBlogViewTotal() {
        return blogMapper.getBlogViewTotal();
    }

    //统计评论总数
    @Override
    public Integer getBlogCommentTotal() {
        return blogMapper.getBlogCommentTotal();
    }

    //统计留言总数
    @Override
    public Integer getBlogMessageTotal() {
        return blogMapper.getBlogMessageTotal();
    }

    //分类页面查询
    @Override
    public List<FirstPageBlogVo> getByTypeId(Long typeId) {
        return blogMapper.getByTypeId(typeId);
    }
}
